package com.fengxing.ams.web.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fengxing.ams.web.action.view.ResponseVO;
import com.fengxing.ams.web.common.IContextManager;

@ControllerAdvice
public class GlobalAction {

	@Autowired
	IContextManager contextManager;
	private Log logger = LogFactory.getLog(GlobalAction.class);	
	
	@ExceptionHandler
	public @ResponseBody ResponseVO exception(Throwable e, HttpServletRequest req) {
		e.printStackTrace();
		logger.error("GlobalAction.exception", e);
		ResponseVO vo = new ResponseVO();
		vo.setSuccess(false);
		vo.setMessage(contextManager.getMessage(e.getMessage()));
		return vo;
	}
}
